<template>
    <div id="orderAll">
        <div class="productCards" v-for="item in orderList" :key="item.id">
            <div class="title">
                <p>OMINI定制</p>
                <div class="status">
                    <h3>交易成功</h3>
                </div>
            </div>
            <div
                class="goods_detail"
                v-for="buyList in item.goods_info"
                :key="buyList.id"
                @click="
                    $router.push({
                        name: 'orderdetail',
                        params: {
                            order_id: item.id,
                        },
                    })
                "
            >
                <div class="pic">
                    <img :src="buyList.s_goods_photos[0].path" />
                </div>
                <div class="detail">
                    <div class="goods_name">
                        <p>{{ buyList.goods_name }}</p>
                        <div class="pn">
                            <span>¥{{ buyList.price }}</span>
                            <span>x1</span>
                        </div>
                    </div>
                    <div class="parameter">
                        <p>淡金色 【10cm】</p>
                    </div>
                    <div class="sevenDay">
                        <p>七天换货</p>
                    </div>
                </div>
            </div>
            <table>
                <tr class="insurance">
                    <td><span>运费险</span></td>
                    <td>
                        <span>确认收货前退货可赔付9元</span>
                        <span>已失效</span>
                    </td>
                </tr>
                <tr class="insurance">
                    <td></td>
                    <td>
                        <span class="total">共1件商品</span>
                        <span>合计：￥{{ item.goods_info[0].price }}</span>
                    </td>
                </tr>
            </table>
            <nut-button color="#000" size="small" plain>删除订单</nut-button>
        </div>
        <div class="nomore"><p>没有更多了哦~</p></div>
    </div>
</template>


<script>
// 引入添加订单数据
import { getOrderList } from "../api/order.js";

export default {
    data() {
        return {
            orderList: [],
        };
    },
    async mounted() {
        const { data } = await getOrderList(1);
        this.orderList = data.result.rows;
        // 返回新数组
        this.orderList.map(function (ele) {
            ele.goods_info = JSON.parse(ele.goods_info);
            return ele;
        });
        // // 改变原数组
        // this.orderList.forEach(function (ele) {
        //   ele.goods_info = JSON.parse(ele.goods_info)
        // })
    },
    watch: {
        //   监听点击后路由传的参数的变化
        async $route() {
            const { data } = await getOrderList(this.$route.params.status);
            this.orderList = data.result.rows;
            // 返回新数组
            this.orderList.map(function (ele) {
                ele.goods_info = JSON.parse(ele.goods_info);
                return ele;
            });
        },
    },
};
</script>

<style lang="scss" scoped>
#orderAll {
    width: 100vw;
    background-color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    .productCards {
        margin-top: 4.267vw;
        width: 345px;
        // height: 69.333vw;
        background-color: rgba(255, 255, 255, 1);
        border-radius: 2.133vw;
        box-shadow: 0px 0.533vw 2.667vw rgb(51 51 51 / 35%);
        font-weight: 700;
        font-size: 16.001px;
        position: relative;
        .nut-button {
            margin: 10px auto;
            margin-left: 260px;
            font-weight: 400;
        }
        .title {
            height: 10.667vw;
            line-height: 10.667vw;
            font-weight: 400;
            font-size: 3.733vw;
            display: flex;
            justify-content: space-between;
            box-sizing: border-box;
            padding: 0vw 2.667vw;
        }
        .goods_detail {
            display: flex;
            justify-content: space-around;
            margin-bottom: 4.8vw;
            .pic {
                width: 26.667vw;
                height: 26.667vw;
                border-radius: 2.667vw;
                overflow: hidden;
                img {
                    width: 100%;
                    height: 100%;
                }
            }
            .detail {
                display: flex;
                flex-direction: column;
                justify-content: space-between;
                .goods_name {
                    display: flex;
                    width: 56vw;
                    overflow: hidden;
                    height: 10.667vw;
                    justify-content: space-between;
                    p {
                        font-size: 3.733vw;
                        font-weight: 400;
                        width: 37.333vw;
                        text-overflow: ellipsis;
                    }
                    .pn {
                        margin-left: 5.333vw;
                        display: flex;
                        flex-direction: column;
                        font-weight: 400;
                        font-size: 3.733vw;
                        color: #999999;
                        text-align: right;
                    }
                }
                .parameter {
                    width: 56vw;
                    p {
                        color: #999999;
                        font-size: 3.467vw;
                        font-weight: 400;
                        line-height: 9.6vw;
                    }
                }
                .sevenDay {
                    width: 17.333vw;
                    height: 5.6vw;
                    background-color: rgba(240, 213, 184, 1);
                    border-radius: 1.067vw;
                    font-weight: 400;
                    font-size: 3.2vw;
                    color: #ffffff;
                    line-height: 5.6vw;
                    text-align: center;
                }
            }
        }
        table {
            margin-left: 13.333vw;
            td:nth-child(1) {
                text-align: right;
                width: 16vw;
            }
            td:nth-child(2) {
                padding: 0 0 0 2.667vw;
            }
        }
        .insurance {
            td:nth-child(1) {
                font-size: 3.467vw;
                font-weight: 400;
                margin-right: 2.667vw;
            }
            td:nth-child(2) {
                display: flex;
                justify-content: space-between;
                margin-top: 4.8vw;
                width: 57.333vw;
                span:nth-child(1) {
                    font-weight: 400;
                    font-size: 3.2vw;
                    color: #999999;
                }
                span:nth-child(2) {
                    font-weight: 400;
                    font-size: 3.2vw;
                    margin-right: 0.267vw;
                }
                .total {
                    width: 32vw;
                    text-align: right;
                }
            }
        }
        .status {
            h3 {
                font-size: 3.2vw;
                color: #d1082a;
            }
        }
    }

    .nomore {
        height: 14.667vw;
        width: 100%;
        color: #8e7e6f;
        text-align: center;
        p {
            line-height: 14.667vw;
            font-weight: 700;
        }
    }
}
</style>